var member = {
    oTable: $('#table'),
    searchOk: $("#ok"),
    resetSearch: $("#reset"),
    init: function () {
        var _self = this;
        this.initConfigTable();
        $(".frost-Data-Mulit").bind("click", function () {
            var ids = _self.oTable.bootstrapTable('getSelections');
            if (ids.length > 0) {
                for (var i in ids) {
                    if (ids[i].froststatus == 1 || ids[i].froststatus == 2) {
                        $.alert({
                            title: false,
                            content: "您选择的账号【" + ids[i].username + "】已被【" + ids[i].froststatusname + "】,不能勾选！",
                            confirmButtonClass: 'btn-consult-alert'
                        });
                        return false;
                    }
                }
                _self.frostone();
            } else {
                $.alert({
                    title: false,
                    content: "请选择您要冻结的账户",
                    confirmButtonClass: 'btn-consult-alert'
                });
            }
        });
        $(".frosttwo-Data-Mulit").bind("click", function () {
            var ids = _self.oTable.bootstrapTable('getSelections');
            if (ids.length > 0) {
                for (var i in ids) {
                    if (ids[i].froststatus == 1 || ids[i].froststatus == 2) {
                        $.alert({
                            title: false,
                            content: "您选择的账号【" + ids[i].username + "】已被【" + ids[i].froststatusname + "】,不能勾选！",
                            confirmButtonClass: 'btn-consult-alert'
                        });
                        return false;
                    }
                }
                _self.frosttwo();
            } else {
                $.alert({
                    title: false,
                    content: "请选择您要拉黑的账户",
                    confirmButtonClass: 'btn-consult-alert'
                });
            }
        });
    },
    initConfigTable: function () {
        var _self = this;
        this.oTable.bootstrapTable({
            url: "/brush/ajaxlist.html",
            method: 'post',
            contentType: "application/x-www-form-urlencoded",
            toolbar: '#toolbar',
            queryParams: this.queryParams,
            pagination: true, //是否分页
            pageSize: 20, //单页记录数
            pageList: [5, 10, 20, 50], //分页步进值
            sidePagination: "server",
            uniqueId: "id",
            columns: [
                {
                    title: "序号",
                    field: "mid",
                    checkbox: true
                },
                {
                    title: "会员ID",
                    field: "id"
                },
                {
                    title: "会员账号",
                    field: "username"
                },
                {
                    title: "会员状态",
                    field: "froststatusname"
                },
                {
                    title: "会员状态",
                    field: "froststatus",
                    visible: false
                },
                {
                    title: "账户金额",
                    field: "amount"
                },
                {
                    title: "推广人数",
                    field: "refercont"
                },
                {
                    title: "已完成任务数量",
                    field: "successcont"
                },
                {
                    title: "被投诉任务数量",
                    field: "tousucont"
                },
                {
                    title: "主动隐藏数量",
                    field: "hiddencont"
                },
                {
                    title: "最后登陆时间",
                    field: "last_login_at"
                },
                {
                    title: "管理操作",
                    field: "action",
                    class: "table-action-class"
                }
            ]
        });
        this.searchOk.bind("click", function () {
            _self.oTable.bootstrapTable("refresh", {pagination: true});
        });
        this.resetSearch.bind("click", function () {
            $('#toolbar').find('input[name]').each(function () {
                $(this).val("");
            });
            $('#toolbar').find('select[name]').each(function () {
                $(this).val("");
                $('.selectpicker').selectpicker('val', '-1');
            });
            _self.oTable.bootstrapTable("refresh", {pagination: true});
        });
    },
    queryParams: function (params) {
        $('#toolbar').find('input[name]').each(function () {
            params[$(this).attr('name')] = $(this).val();
        });
        $('#toolbar').find('select[name]').each(function () {
            params[$(this).attr('name')] = $(this).val();
        });
        return params;
    },
    shifttodrawal: function (id) {
        var _self = this;
        var selects = _self.oTable.bootstrapTable('getRowByUniqueId', id);
        $("#amount").text(selects.amount);
        $("#modal-shifttodrawal").modal("show");
        $("#operateBtn").unbind("click").bind("click", function (e) {
            var params = {
                id: id,
                number: $('#number').val()
            };
            $.post("/brush/shifttodrawal.html", params, function (e) {
                if (e.status === true) {
                    $("#modal-shifttodrawal").modal("hide");
                    $('#number').val("");
                    _self.oTable.bootstrapTable("refresh", {pagination: true});
                } else {
                    $.alert({
                        title: false,
                        content: e.message,
                        confirmButtonClass: 'btn-consult-alert'
                    });
                }
            }, "json");
        });
    },
    //冻结
    frostone: function () {
        var _self = this;
        $("#modal-frostone").modal("show");
        $("#frostoneBtn").unbind("click").bind("click", function (e) {
            var item = [],
                    ids = _self.oTable.bootstrapTable('getSelections');
            $.each(ids, function (k, v) {
                item.push(v.id);
            });
            var params = {
                id: item.join(","),
                number: $("#deadline").val(),
                note: $("#note").val()
            };
            if (params.number && params.note) {
                $.post("/brush/frost.html", params, function (e) {
                    if (e.status === true) {
                        $("#modal-frostone").modal("hide");
                        $("#number").val("");
                        $("#note").val("");
                        _self.oTable.bootstrapTable("refresh", {pagination: true});
                    } else {
                        $.alert({
                            title: false,
                            content: e.message,
                            confirmButtonClass: 'btn-consult-alert'
                        });
                    }
                }, "json");
            } else {
                $.alert({
                    title: "提示",
                    content: "请填写冻结期限和冻结说明",
                    confirmButtonClass: 'btn-consult-alert'
                });
            }
        });
    },
    //拉黑
    frosttwo: function () {
        var _self = this;
        $("#modal-frosttwo").modal("show");
        $("#frosttwoBtn").unbind("click").bind("click", function (e) {
            var item = [],
                    ids = _self.oTable.bootstrapTable('getSelections');
            $.each(ids, function (k, v) {
                item.push(v.id);
            });
            var params = {
                id: item.join(","),
                note: $("#note2").val()
            };
            if (params.note) {
                $.post("/brush/frost2.html", params, function (e) {
                    if (e.status === true) {
                        $("#modal-frosttwo").modal("hide");
                        $("#note2").val("");
                        _self.oTable.bootstrapTable("refresh", {pagination: true});
                    } else {
                        $.alert({
                            title: false,
                            content: e.message,
                            confirmButtonClass: 'btn-consult-alert'
                        });
                    }
                }, "json");
            } else {
                $.alert({
                    title: "提示",
                    content: "请填写拉黑说明",
                    confirmButtonClass: 'btn-consult-alert'
                });
            }
        });
    }
};
var shopmember = {
    oTable: $('#table'),
    searchOk: $("#ok"),
    resetSearch: $("#reset"),
    init: function () {
        var _self = this;
        this.initConfigTable();
        $(".frost-Data-Mulit").bind("click", function () {
            var ids = _self.oTable.bootstrapTable('getSelections');
            if (ids.length > 0) {
                for (var i in ids) {
                    if (ids[i].froststatus == 1 || ids[i].froststatus == 2) {
                        $.alert({
                            title: false,
                            content: "您选择的账号【" + ids[i].username + "】已被【" + ids[i].froststatusname + "】,不能勾选！",
                            confirmButtonClass: 'btn-consult-alert'
                        });
                        return false;
                    }
                }
                _self.frostone();
            } else {
                $.alert({
                    title: false,
                    content: "请选择您要冻结的账户",
                    confirmButtonClass: 'btn-consult-alert'
                });
            }
        });
        $(".frosttwo-Data-Mulit").bind("click", function () {
            var ids = _self.oTable.bootstrapTable('getSelections');
            if (ids.length > 0) {
                for (var i in ids) {
                    if (ids[i].froststatus == 1 || ids[i].froststatus == 2) {
                        $.alert({
                            title: false,
                            content: "您选择的账号【" + ids[i].username + "】已被【" + ids[i].froststatusname + "】,不能勾选！",
                            confirmButtonClass: 'btn-consult-alert'
                        });
                        return false;
                    }
                }
                _self.frosttwo();
            } else {
                $.alert({
                    title: false,
                    content: "请选择您要拉黑的账户",
                    confirmButtonClass: 'btn-consult-alert'
                });
            }
        });
        $(".deblocking-Data-Mulit").bind("click", function () {
            var ids = _self.oTable.bootstrapTable('getSelections');
            var item = [];
            if (ids.length > 0) {
                for (var i in ids) {
                    item.push(ids[i].id);
                    if (ids[i].froststatus == 1 || ids[i].froststatus == 0) {
                        $.alert({
                            title: false,
                            content: "您选择的账号【" + ids[i].username + "】是正常或冻结账号,不能勾选！",
                            confirmButtonClass: 'btn-consult-alert'
                        });
                        return false;
                    }
                }
                $.post("/brush/deblocking.html", { id: item.join(",")}, function (e) {
                    if (e.status === true) {
                        $.alert({
                             title: false,
                            content: "解封账号成功！",
                            confirmButtonClass: 'btn-consult-alert'
                        });
                        _self.oTable.bootstrapTable("refresh", {pagination: true});
                    } else {
                        $.alert({
                            title: false,
                            content: e.message,
                            confirmButtonClass: 'btn-consult-alert'
                        });
                    }
                }, "json");
            } else {
                $.alert({
                    title: false,
                    content: "请选择您要解封的账户",
                    confirmButtonClass: 'btn-consult-alert'
                });
            }
        });
    },
    initConfigTable: function () {
        var _self = this;
        this.oTable.bootstrapTable({
            url: "/brush/ajaxmerlist.html",
            method: 'get',
            contentType: "application/x-www-form-urlencoded",
            toolbar: '#toolbar',
            buttons: ".tools",
            queryParams: this.queryParams,
            pagination: true, //是否分页
            pageSize: 20, //单页记录数
            pageList: [5, 10, 20, 50], //分页步进值
            sidePagination: "server",
            uniqueId: "id",
            clickToSelect: true,
            toolbarAlign: "left",
            columns: [
                {
                    title: "序号",
                    field: "mid",
                    checkbox: true
                },
                {
                    title: "商户ID",
                    field: "id"
                },
                {
                    title: "商户账号",
                    field: "username"
                },
                {
                    title: "商户状态",
                    field: "froststatusname"
                },
                {
                    title: "商户状态",
                    field: "froststatus",
                    visible: false
                },
                {
                    title: "商户级别",
                    field: "grade"
                },
                {
                    title: "真实姓名",
                    field: "truename"
                },
                {
                    title: "账户金额",
                    field: "amount"
                },
                {
                    title: "返利金额",
                    field: "rebate_amount"
                },
                {
                    title: "注册时间",
                    field: "created_at"
                },
                {
                    title: "发布任务量",
                    field: "taskcont"
                },
                {
                    title: "管理操作",
                    field: "action",
                    class: "table-action-class"
                }
            ]
        });
        this.searchOk.bind("click", function () {
            _self.oTable.bootstrapTable("refresh", {pagination: true});
        });
        this.resetSearch.bind("click", function () {
            $('#toolbar').find('input[name]').each(function () {
                $(this).val("");
            });
            $('#toolbar').find('select[name]').each(function () {
                $(this).val("");
                $('.selectpicker').selectpicker('val', '-1');
            });
            _self.oTable.bootstrapTable("refresh", {pagination: true});
        });
    },
    queryParams: function (params) {
        $('#toolbar').find('input[name]').each(function () {
            params[$(this).attr('name')] = $(this).val();
        });
        $('#toolbar').find('select[name]').each(function () {
            params[$(this).attr('name')] = $(this).val();
        });
        return params;
    },
    editgrade: function (id) {
        var _self = this;
        var selects = _self.oTable.bootstrapTable('getRowByUniqueId', id);
        $("#gradename").text(selects.grade);
        $("#modal-editgrade").modal("show");
        $("#operateBtn").unbind("click").bind("click", function (e) {
            var params = {
                id: id,
                gradeid: $('.selectpicker').selectpicker('val')
            };
            $.post("/brush/editgrade.html", params, function (e) {
                if (e.status === true) {
                    $("#modal-editgrade").modal("hide");
                    $('.selectpicker').selectpicker('val', '-1');
                    _self.oTable.bootstrapTable("refresh", {pagination: true});
                } else {
                    $.alert({
                        title: false,
                        content: e.message,
                        confirmButtonClass: 'btn-consult-alert'
                    });
                }
            }, "json");
        });
    },
    //冻结
    frostone: function () {
        var _self = this;
        $("#modal-frostone").modal("show");
        $("#frostoneBtn").unbind("click").bind("click", function (e) {
            var item = [],
                    ids = _self.oTable.bootstrapTable('getSelections');
            $.each(ids, function (k, v) {
                item.push(v.id);
            });
            var params = {
                id: item.join(","),
                number: $("#number").val(),
                note: $("#note").val()
            };
            if (params.number && params.note) {
                $.post("/brush/frost.html", params, function (e) {
                    if (e.status === true) {
                        $("#modal-frostone").modal("hide");
                        $("#number").val("");
                        $("#note").val("");
                        _self.oTable.bootstrapTable("refresh", {pagination: true});
                    } else {
                        $.alert({
                            title: false,
                            content: e.message,
                            confirmButtonClass: 'btn-consult-alert'
                        });
                    }
                }, "json");
            } else {
                $.alert({
                    title: "提示",
                    content: "请填写冻结期限和冻结说明",
                    confirmButtonClass: 'btn-consult-alert'
                });
            }
        });
    },
    //拉黑
    frosttwo: function () {
        var _self = this;
        $("#modal-frosttwo").modal("show");
        $("#frosttwoBtn").unbind("click").bind("click", function (e) {
            var item = [],
                    ids = _self.oTable.bootstrapTable('getSelections');
            $.each(ids, function (k, v) {
                item.push(v.id);
            });
            var params = {
                id: item.join(","),
                note: $("#note2").val()
            };
            if (params.note) {
                $.post("/brush/frost2.html", params, function (e) {
                    if (e.status === true) {
                        $("#modal-frosttwo").modal("hide");
                        $("#note2").val("");
                        _self.oTable.bootstrapTable("refresh", {pagination: true});
                    } else {
                        $.alert({
                            title: false,
                            content: e.message,
                            confirmButtonClass: 'btn-consult-alert'
                        });
                    }
                }, "json");
            } else {
                $.alert({
                    title: "提示",
                    content: "请填写拉黑说明",
                    confirmButtonClass: 'btn-consult-alert'
                });
            }
        });
    }
};
